﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace DFYE.Web.Areas.manage.Controllers
{
    using DFYE.Web.Models;
    using JULONG.WEB.Library;

    public class studentClassController : Controller
    {
        //
        // GET: /manage/studentClass/
        DataSession<entityDBContainer, studentClass> db = new DataSession<entityDBContainer, studentClass>();
        public ActionResult Index()
        {
            
            return View(db.query());
        }



        //
        // GET: /manage/studentClass/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /manage/studentClass/Create

        [HttpPost]
        public ActionResult Create(FormCollection collection)
        {

            studentClass st = new studentClass();
            TryUpdateModel(st);

            try
            {
                
                // TODO: Add insert logic here
                db.insert(st);

                return RedirectToAction("Index");
            }
            catch
            {
                return View(st);
            }
        }
        //
        // GET: /manage/studentClass/Edit/5
 
        public ActionResult Edit(int id)
        {
            studentClass st = db.get(d=>d.ID==id);
            if (st == null) return RedirectToAction("index");

            ViewData.Model = st;
            return View();
        }

        //
        // POST: /manage/studentClass/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            studentClass st = db.get(d => d.ID == id);
            TryUpdateModel(st);
            try
            {
                db.save();

                return RedirectToAction("Index", new {staute = true });

            }
            catch
            {
                return View(st);
            }
        }



        //
        // POST: /manage/studentClass/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                db.delete(d => d.ID == id);

                // TODO: Add delete logic here

                return RedirectToAction("Index", new { staute = true });
            }
            catch
            {
                return View();
            }
        }
    }
}
